from variable import Variable
from operate import pic_click, press
import time
from util import go_position, go_back, conform_tili


def fightRoles():
    for i in Variable.fight_roles["person"]:
        print(f"开始获得角色碎片-{i}")
        go_position("fight_roles")
        for j in range(3):
            if not pic_click(f"images/fight/fight_roles/{i}.png", confidence=0.9):
                press("left")
                time.sleep(1.5)
            else:
                break
        pic_click(src="images/fight/fight_roles/auto_fight.png")
        if not pic_click(src="images/fight/max.png"):
            time.sleep(2)
            go_back()
            continue
        if not pic_click(src="images/fight/ok_fight.png"):
            time.sleep(2)
            go_back()
            continue
        if conform_tili():
            pic_click(src="images/fight/max.png")
            pic_click(src="images/fight/ok_fight.png")
        if not pic_click(src="images/fight/ok.png"):
            time.sleep(2)
            go_back()
            continue
        go_back()
        time.sleep(1)
    print("角色碎片完成")
    go_back()
